package BanyuanClub.Work.Day0224.TextString;

import java.util.Arrays;

public class MyString {
    public static void main(String[] args) {
        String s = " I love Java ";

        //trim 字符串中字符数量
        System.out.println(s.length()-s.trim().length());

        //charAt 打印指定下标处字符
        System.out.println(s.charAt(5));

        //substring 截取
        System.out.println(s.substring(
                s.indexOf("I"),s.indexOf("J")
                ));

        //contains 检测字符串中是否包含"特定字符"
        System.out.println(s.contains("V"));
        String s1 = "shfGTRGJjkHjkJHjKJhFYVvyg";

        //toCharArray 将字符串转为char数组
        char[] carr = s1.toCharArray();
        System.out.println(Arrays.toString(carr));
        boolean b = false;
        for (int i = 0; i < carr.length; i++) {
            if (carr[i] >= 'a' && carr[i] <= 'z'){
                carr[i] -= 32;
            }else if (carr[i] >= 'A' && carr[i] <= 'Z'){
                carr[i] += 32;
            }else {
                b = true;
                break;
            }
        }
        if (!b){
            System.out.println(Arrays.toString(carr));
        }else {
            System.out.println("转换失败");
        }
        StringBuilder sb = new StringBuilder("djf;aiehrfddd;fjeddddfafnefnd");

        //reverse 将字符串反转
        String s2 = sb.reverse().toString();
        System.out.println(s2);

        //split 按指定字符将字符串进行分割
        String s3 = "11#2#333#444#55";
        String[] c = s3.split("#");
        int sum = 0;
        for (String s4:c
             ) {
            sum += Integer.parseInt(s4);
        }
        System.out.println(sum);
    }
}
